package com.demo.controller;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.demo.common.constant.DictKeys;
import com.demo.service.UploadService;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.upload.UploadFile;
/**
 * 文件上传
 * @author Emode
 *
 */
public class UploadController extends Controller{
	/**
	 * 默认是保存到	/WebContent/files/upload
	 * 否则保存到	/WebContent/WEB-INF/files/upload
	 */
	private static Logger log = Logger.getLogger(UploadController.class);
	public String pathType;
	public void index(){
		String channel = getPara("channel");
		Map<String, String[]> map = getParaMap();
		channel = channel==null?"1":channel;
		StringBuilder sb = new StringBuilder();
		if(null==pathType||pathType.isEmpty()||pathType.equals("webRoot")){
			//sb.append(PathKit.getWebRootPath()).append(File.separator).append("upload").append(File.separator).append("images");
			sb.append(File.separator).append("images");
		}else{
			//pathType = "webInfo";
			//sb.append(PathKit.getWebRootPath()).append(File.separator).append("upload").append(File.separator).append("images");
		}
		System.out.println(sb.toString());
		List<UploadFile> files = getFiles(sb.toString(),DictKeys.max_post_size,"UTF-8");
		List<Map<String, Object>> list = UploadService.serivce.upload(sb.toString(), channel, files);
		System.out.println("上传"+list);
		renderJson("Ok");
		
	}

}
